home *** CD-ROM | disk | FTP | other *** search
/ Chip 2006 June (Extra) / CHIP 2006-06.3.iso / program / opensource / GetGnuWin32-0.6.13.exe / GetGnuWin32 / download.bat next >
Encoding:
DOS Batch File  |  2006-05-04  |  7.4 KB  |  254 lines

  1. :: -------------------------------------------------------------------
  2. :: 
  3. :: download.bat -- Maintain a small local gnuwin32 package archive
  4. ::                 whithin the cmd console of windows XP
  5. :: 
  6. :: author : Mathias Michaelis <michaelis@tcnet.ch>
  7. :: date   : May 4, 2006
  8. :: version: 0.6.13
  9. ::
  10. :: Copyright (c) 2006 by Mathias Michaelis, <michaelis@tcnet.ch>
  11. ::
  12. :: -------------------------------------------------------------------
  13. ::
  14. :: Permission is granted to copy, distribute and/or modify this document
  15. :: under the terms of the GNU Free Documentation License, Version 1.2
  16. :: or any later version published by the Free Software Foundation;
  17. :: with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
  18. :: Texts.  A copy of the license is included in the file LICENSE.TXT
  19. ::
  20. ::
  21. :: Acknowledgments
  22. :: ---------------
  23. ::
  24. :: See file README.TXT in this directory. Thanks to all who advised me,
  25. :: gave me some hints, sent me some patches or encouraged me to go on!
  26. ::
  27. @echo off
  28. setlocal ENABLEEXTENSIONS
  29. set LC_ALL=C
  30.  
  31. ::
  32. :: Customization
  33. :: -------------
  34. ::
  35. :: Select one or more of the following mirrors first! Please separate
  36. :: the mirrors by space, e.g. GNUWIN32_MIRROR="umn unc".
  37. ::
  38. :: aleron   (US)
  39. :: belnet   (BE)
  40. :: easynews (US)
  41. :: heanet   (IE)
  42. :: internap (US)
  43. :: jaist    (JP)
  44. :: keihanna (JP)
  45. :: kent     (UK)
  46. :: mesh     (DE)
  47. :: optusnet (AU)
  48. :: ovh      (FR)
  49. :: puzzle   (CH)
  50. :: switch   (CH)
  51. :: umn      (US)
  52. :: unc      (US)
  53. :: voxel    (US)
  54. ::
  55. if .%GNUWIN32_MIRROR%==. set GNUWIN32_MIRROR=umn
  56.  
  57. :: 
  58. ::
  59. :: Process command line options. This can be a list of some above
  60. :: mentioned mirrors ans/or the verbose option switch -v.
  61. ::
  62. set GNUWIN32_CMDLINE_MIRROR=
  63.  
  64. :command_line
  65. if .%1==. goto command_line_end
  66. if "%1"=="-v" goto set_verbose
  67. set GNUWIN32_CMDLINE_MIRROR=%GNUWIN32_CMDLINE_MIRROR% %1
  68. shift
  69. goto command_line
  70.  
  71. :set_verbose
  72. set GNUWIN32_VERBOSE=TRUE
  73. shift
  74. goto command_line
  75.  
  76. ::
  77. :: If command line options were specified, overwrite environment
  78. :: variables
  79. ::
  80. :command_line_end
  81. if "%GNUWIN32_CMDLINE_MIRROR%"=="" goto environment
  82. set GNUWIN32_MIRROR=%GNUWIN32_CMDLINE_MIRROR:~1%
  83. set GNUWIN32_LOAD=
  84. set GNUWIN32_CMDLINE_MIRROR=
  85.  
  86. ::
  87. :: After the mirrors are known, the download address of that mirrors
  88. :: can be constructed (if not already done):
  89. ::
  90. :environment
  91. if not .%GNUWIN32_LOAD%==. goto set_wgetrc
  92. set GNUWIN32_LOAD=http://%GNUWIN32_MIRROR:"=%.dl.sourceforge.net/sourceforge/gnuwin32/
  93. set GNUWIN32_LOAD=%GNUWIN32_LOAD: =.dl.sourceforge.net/sourceforge/gnuwin32/ http://%
  94.  
  95. ::
  96. :: Perhaps the user has specified her/his own .wgetrc file by means
  97. :: of the WGETRC environment variable. If not, then use the one in
  98. :: the local bin directory
  99. ::
  100. :set_wgetrc
  101. if ".%WGETRC%"=="." set WGETRC=%CD%\bin\wget.ini
  102.  
  103. ::
  104. :: If we are in verbose mode, tell what we're going to do
  105. ::
  106. if "%GNUWIN32_VERBOSE%"=="" goto clean_old_lists
  107.  
  108. echo =
  109. echo = URL of file list:
  110. echo =  https://sourceforge.net/project/showfiles.php?group_id=23617
  111. echo =
  112. echo = List of mirrors (high priority first):
  113. echo =  %GNUWIN32_MIRROR%
  114. echo =
  115. echo = List of URLs (high priority first):
  116. echo %GNUWIN32_LOAD% >loadlist.txt
  117. bin\sed "s/  *$//;s/.*/=  &/;s/[^ =] /\n=  /g" loadlist.txt
  118. echo =
  119. del loadlist.txt
  120.  
  121. ::
  122. :: Clean up old filelists etc.
  123. ::
  124. :clean_old_lists
  125. if exist filelist.txt del filelist.txt
  126. if exist packages.txt del packages.txt
  127.  
  128. ::
  129. :: First, get the filelist form the official project site on sourceforge.net
  130. ::
  131. if not "%GNUWIN32_VERBOSE%"=="" echo = Downloading file list from sourceforge.net ...
  132. bin\wget --ca-certificate=bin\cacert.pem -O project.html https://sourceforge.net/project/showfiles.php?group_id=23617
  133. if exist project.html goto normalize
  134. echo Couldn't download gnuwin32 project site from sourceforge.net
  135. goto bye
  136.  
  137. ::
  138. :: Normalize filetable.html: Every tag has to be in its own line. Empty lines
  139. :: aren't allowed
  140. ::
  141. :normalize
  142. if not "%GNUWIN32_VERBOSE%"=="" echo = Analysing file list ...
  143. bin\sed -n "s/>/>\n/g;s/</\n</g;s/\(\s*\n\)\+\s*/\n/g;s/^\n\+//;s/\n\+$//;s/^\s\+//;s/.\+/&/p" project.html >normal.html
  144. del project.html
  145.  
  146. ::
  147. :: Convert the normalized HTML file in plain text. Take only the
  148. :: information that is relevant here: The package list. Because
  149. :: This procedure depends very much on the way the HTML file is
  150. :: programmed. That's why it's a bit risky. If this script is not
  151. :: up-to-date, this step may fail!
  152. ::
  153. bin\sed -n "/^<tr\s\+class\s*=\s*""""package""""\s*>/{n;n;n;s/.*/ &/p};/^<a href=""""http:\/\/prdownloads.sourceforge.net\/gnuwin32\/\(.*-\(bin\|doc\|lib\|dep\)\.zip\)?download"""">$/Is//\1/p" normal.html >filelist.tmp
  154. bin\sed "/^ /d" filelist.tmp >filelist.txt
  155. del normal.html
  156.  
  157. ::
  158. :: Assume: filelist.txt is already sorted by filenames and fileversion
  159. :: so that new versions are listed first.
  160. ::
  161. :: Now create a package list from the files with the newest versions
  162. ::
  163. :: bin\sed -n "/^[^ ]/s/\(.*\)-...\.zip/\1/p" filelist.txt >packages.tmp
  164. :: bin\sed ":x;N;s/^\(\([^-]*-[^[:digit:]]\)*[^-]*\)\(-[[:digit:]].*\)\?\n\1\(-[[:digit:]].*\)\?$/\1\3/;tx;P;D" packages.tmp >packages.txt
  165. ::
  166. :: New: filelist.tmp contains also package information. This simplifies
  167. :: the process of generating a package list.
  168. ::
  169. bin\sed -n "/^ /{n;s/\(.*\)-...\.zip/\1/p}" filelist.tmp >packages.txt
  170.  
  171. ::
  172. :: Cancel all packages which name are listed within the include.txt and
  173. :: the exclude.txt files.
  174. ::
  175. if exist include.txt bin\sed -n "s/\s*#.*$//;tx;:x;s/^\s*$//;t;s/\s*//g;p" include.txt >include.tmp
  176. if exist include.tmp bin\sed "s/^\(\([^-]*-[^[:digit:]]\)*[^-]*\).*$/\1 -/" include.tmp >exclude.tmp
  177. if exist exclude.txt bin\sed -n "s/\s*#.*$//;tx;:x;s/^\s*$//;t;s/^\s*\([^[:space:]]*\)\s*$/\1 -/p" exclude.txt >>exclude.tmp
  178. if not exist exclude.tmp goto add_include
  179.  
  180. bin\sort -u packages.txt exclude.tmp -o packages.tmp
  181. bin\sed "/^.* -$/{:x;N;s/^\([^\n]*\) -\n\1-[[:digit:]].*$/\1 -/I;tx;D}" packages.tmp >packages.txt
  182. del packages.tmp
  183. del exclude.tmp
  184.  
  185. ::
  186. :: Add packages in include.txt
  187. ::
  188. :add_include
  189. if not exist include.tmp goto shuffle
  190. copy include.tmp+packages.txt packages.tmp >nul
  191. del packages.txt
  192. del include.tmp
  193. ren packages.tmp packages.txt
  194.  
  195. ::
  196. :: Shuffle package list and file list
  197. ::
  198. :shuffle
  199. bin\sed "s/^.*[^-]$/&-/" packages.txt >packages.tmp
  200. bin\sort filelist.txt packages.tmp -o filelist.tmp
  201. del packages.tmp
  202.  
  203. ::
  204. :: Cancel all files which don't belong to a package
  205. ::
  206. bin\sed -n "h;N;s/^\([^\n]\+\)\n\1/\1/;tx;D;:x;G;P;D" filelist.tmp >filelist.txt
  207. del filelist.tmp
  208.  
  209. ::
  210. :: Download the desired files from the server
  211. ::
  212. if not "%GNUWIN32_VERBOSE%"=="" echo = Starting download of all files found whithin the file list ...
  213. if not exist packages goto makepackages
  214. if not exist oldpacks goto makeoldpacks
  215.  
  216. move /y packages\*.* oldpacks >nul
  217. rmdir /s /q packages
  218. goto makepackages
  219.  
  220. :makeoldpacks
  221. ren packages oldpacks
  222.  
  223. :makepackages
  224. mkdir packages
  225.  
  226. :download
  227. echo %GNUWIN32_LOAD% >loadlist.tmp
  228. bin\sed "s/  *$//;s/ /\n/g" loadlist.tmp >loadlist.txt
  229. del loadlist.tmp
  230. cd packages
  231. for /f %%f in (..\filelist.txt) do (
  232.     if not exist ..\oldpacks\%%f (
  233.         for /f %%m in (..\loadlist.txt) do (
  234.             if not exist %%f ..\bin\wget "%%m%%f"
  235.         )
  236.     ) else (
  237.         move /y ..\oldpacks\%%f .
  238.     )
  239. )
  240. cd ..
  241. del loadlist.txt
  242.  
  243. ::
  244. :: Clean up things
  245. ::
  246. if not exist oldpacks goto bye
  247. dir /b oldpacks >oldpacks.txt
  248. bin\test -s oldpacks.txt
  249. if errorlevel 1 rmdir /s /q oldpacks
  250. if exist oldpacks.txt del oldpacks.txt
  251.  
  252. :bye
  253. endlocal
  254.